package net.lijingye.education.service.impl;

import net.lijingye.education.dao.LessonDao;
import net.lijingye.education.entity.Lesson;
import net.lijingye.education.entity.PPT;
import net.lijingye.education.entity.Source;
import net.lijingye.education.entity.Topic;
import net.lijingye.education.exception.DaoException;
import net.lijingye.education.exception.ObjectNotExistsException;
import net.lijingye.education.service.LessonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by LijingYe on 2016/4/4.
 */
@Service
@Transactional
public class LessonServiceImpl implements LessonService {
    @Autowired
    private LessonDao lessonDao;

    @Override
    public Lesson getLessonById(String lessonId) throws DaoException, ObjectNotExistsException {
        Lesson lesson = lessonDao.getById(lessonId);
        if (null == lesson) {
            throw new ObjectNotExistsException("Lesson `" + lessonId + "`");
        }
        return lesson;
    }

    @Override
    public List<PPT> getLessonPPTListById(String lessonId) throws DaoException, ObjectNotExistsException {
        Lesson lesson = this.getLessonById(lessonId);
        List<PPT> pptList = lesson.getPPTList();
        return pptList;
    }

    @Override
    public List<Source> getLessonSourceListById(String lessonId) throws DaoException, ObjectNotExistsException {
        Lesson lesson = this.getLessonById(lessonId);
        List<Source> sourceList = lesson.getSourceList();
        return sourceList;
    }

    @Override
    public List<Topic> getLessonTopicListById(String lessonId) throws DaoException, ObjectNotExistsException {
        Lesson lesson = this.getLessonById(lessonId);
        List<Topic> topicList = lesson.getTopicList();
        return topicList;
    }
}
